using System;
using System.Collections.Generic;
using MSOffice = Microsoft.Office.Core;
using MSOutlook = Microsoft.Office.Interop.Outlook;

namespace Microsoft.Sample.Outlook.Utility
{
    public sealed class ToolboxTextBox : ToolbarControl
	{
		public ToolboxTextBox(string ID)
			: base(ID)
		{
		}

		public ToolboxTextBox(string ID, string caption)
			: base(ID, caption)
		{
		}

		public ToolboxTextBox(string ID, string caption, string tooltip)
			: base(ID, caption, tooltip)
		{
		}

		internal override void Attach(MSOffice.CommandBar bar, WindowAdapter window)
		{
			MSOffice.CommandBarControl tbx = FindControl<MSOffice.CommandBarControl>(bar);

			if (tbx == null)
			{
				tbx = (MSOffice.CommandBarControl)bar.Controls.Add(
					MSOffice.MsoControlType.msoControlEdit,
					Type.Missing, Type.Missing,
					this.Position != null ? this.Position.Value : Type.Missing, true);

				tbx.Parameter = this.ID;
				tbx.Tag = Guid.NewGuid().ToString();
			}

			tbx.Caption = this.Caption;
			tbx.TooltipText = this.ToolTip;

			AddControl(tbx);
			window.Close += delegate(object sender, EventArgs args)
			{
				RemoveControl(tbx);
			};

		}

	}
}
